package cn.edu.njpi.utils;

import cn.edu.njpi.wordcount.WordCountDriver;

import java.io.File;
import java.io.IOException;

/**
 * @author 朱宗辉
 * @version V1.0
 * @Package cn.edu.njpi.utils
 * @date 2021/12/12 上午12:44
 */
public class WordCountUtils {
    public static boolean result = false;

    public static void wordcount(String input, String output) throws IOException, InterruptedException, ClassNotFoundException {
        String[] split = input.split("\\/");
        // 文件名
        String inputFile = split[split.length - 1];
        File file = new File(output);
        file.mkdir();
        HDFSUtils.deleteOutput("/input");
        HDFSUtils.deleteOutput("/output");
        HDFSUtils.mkdir("/input");
        HDFSUtils.uploadInputFile(input, "/input/" + inputFile);
        WordCountDriver.main(split);
        HDFSUtils.getOutput("/output/part-r-00000", output);
        HDFSUtils.deleteOutput("/input");
        HDFSUtils.deleteOutput("/output");
        System.exit(result ? 0 : 1);
    }
}
